package emergency.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whu.zj.MyApplication;
import com.whu.zj.R;

import java.util.ArrayList;
import java.util.List;

import emergency.dto.Alert;

/**
 * 预警内容查看
 * Created by Administrator on 2016/3/15.
 */
public class EmergencyTypeAdapter extends BaseAdapter{

    List<Alert> alerts = new ArrayList<Alert>();

    public void setAlerts(List<Alert> alerts) {
        this.alerts = alerts;
    }

    @Override
    public int getCount() {
        return alerts.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(MyApplication.share(), R.layout.item_alertemergencytype,null);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.id_tv_type);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.id_tv_content);
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        Alert alert = alerts.get(position);
        String type = alert.getAlertType();
        String content = alert.getAlertContent();
        String content_real = content.replace("<br/>","\n");

        viewHolder.tv_type.setText(type==null?"无":type);
        viewHolder.tv_content.setText(content==null?"无":content_real);
        return convertView;
    }

    public static class ViewHolder
    {
        public TextView tv_type;
        public TextView tv_content;
    }
}
